﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;

namespace luanvanFinal
{
    class clsReqRisk
    {
        int id;
        int idProject;
        String idReq;
        int cusCos;
        int cusFun;
        int cusCom;
        int cusGen;
        int cusDoc;
        int busCos;
        int busFun;
        int busGen;
        int busDoc;
        int busUnd;
        int busEx;
        int busDev;
        int impGen;
        int impDoc;
        int impRes;
        int impTec;
        int impEx;
        int impDev;
        int quaGen;
        int quaRes;
        int quaUnd;
        int quaEx;
        int quaDev;
        int quaCon;
        int sumCos;
        int sumBus;
        int sumImp;
        int sumQua;
        int total;
        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        public int IdProject
        {
            get { return idProject; }
            set { idProject = value; }
        }
        public String IdReq
        {
            get { return idReq; }
            set { idReq = value; }
        }
        public int CusCos
        {
            get { return cusCos; }
            set { cusCos = value; }
        }
        public int CusCom
        {
            get { return cusCom; }
            set { cusCom = value; }
        }
        public int CusFun
        {
            get { return cusFun; }
            set { cusFun = value; }
        }

        public int CusGen
        {
            get { return cusGen; }
            set { cusGen = value; }
        }
        public int CusDoc
        {
            get { return cusDoc; }
            set { cusDoc = value; }
        }
        public int BusCos
        {
            get { return busCos; }
            set { busCos = value; }
        }
        public int BusFun
        {
            get { return busFun; }
            set { busFun = value; }
        }
        public int BusGen
        {
            get { return busGen; }
            set { busGen = value; }
        }
        public int BusDoc
        {
            get { return busDoc; }
            set { busDoc = value; }
        }
        public int BusUnd
        {
            get { return busUnd; }
            set { busUnd = value; }
        }
        public int BusEx
        {
            get { return busEx; }
            set { busEx = value; }
        }
        public int BusDev
        {
            get { return busDev; }
            set { busDev = value; }
        }
        public int ImpGen
        {
            get { return impGen; }
            set { impGen = value; }
        }
        public int ImpDoc
        {
            get { return impDoc; }
            set { impDoc = value; }
        }
        public int ImpRes
        {
            get { return impRes; }
            set { impRes = value; }
        }
        public int ImpTec
        {
            get { return impTec; }
            set { impTec = value; }
        }
        public int ImpEx
        {
            get { return impEx; }
            set { impEx = value; }
        }
        public int ImpDev
        {
            get { return impDev; }
            set { impDev = value; }
        }
        public int QuaGen
        {
            get { return quaGen; }
            set { quaGen = value; }
        }
        public int QuaRes
        {
            get { return quaRes; }
            set { quaRes = value; }
        }
        public int QuaUnd
        {
            get { return quaUnd; }
            set { quaUnd = value; }
        }
        public int QuaEx
        {
            get { return quaEx; }
            set { quaEx = value; }
        }
        public int QuaDev
        {
            get { return quaDev; }
            set { quaDev = value; }
        }
        public int QuaCon
        {
            get { return quaCon; }
            set { quaCon = value; }
        }
        public int SumCos
        {
            get { return sumCos; }
            set { sumCos = value; }
        }
        public int SumBus
        {
            get { return sumBus; }
            set { sumBus = value; }
        }
        public int SumImp
        {
            get { return sumImp; }
            set { sumImp = value; }
        }
        public int SumQua
        {
            get { return sumQua; }
            set { sumQua = value; }
        }
        public int Total
        {
            get { return total; }
            set { total = value; }
        }
        public clsReqRisk()
        {
            id = 0;
            idProject = 0;
            idReq = "";
            cusCos = 0;
            cusFun = 0;
            cusCom = 0;
            cusGen = 0;
            cusDoc = 0;
            busCos = 0;
            busFun = 0;
            busGen = 0;
            busDoc = 0;
            busUnd = 0;
            busEx = 0;
            busDev = 0;
            impGen = 0;
            impDoc = 0;
            impRes = 0;
            impTec = 0;
            impEx = 0;
            impDev = 0;
            quaGen = 0;
            quaRes = 0;
            quaUnd = 0;
            quaEx = 0;
            quaDev = 0;
            sumCos = 0;
            sumBus = 0;
            sumImp = 0;
            sumQua = 0;
            total = 0;
        }
        public void insertReqRisk()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("insertReqRisk", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idProject", SqlDbType.Int).Value = this.idProject;
                sqlcmd.Parameters.Add("@idReq", SqlDbType.NVarChar).Value = this.idReq;
                sqlcmd.Parameters.Add("@cusCos", SqlDbType.Int).Value = this.cusCos;
                sqlcmd.Parameters.Add("@cusFun", SqlDbType.Int).Value = this.cusFun;
                sqlcmd.Parameters.Add("@cusCom", SqlDbType.Int).Value = this.cusCom;
                sqlcmd.Parameters.Add("@cusGen", SqlDbType.Int).Value = this.cusGen;
                sqlcmd.Parameters.Add("@cusDoc", SqlDbType.Int).Value = this.cusDoc;
                sqlcmd.Parameters.Add("@busCos", SqlDbType.Int).Value = this.busCos;
                sqlcmd.Parameters.Add("@busFun", SqlDbType.Int).Value = this.busFun;
                sqlcmd.Parameters.Add("@busGen", SqlDbType.Int).Value = this.busGen;
                sqlcmd.Parameters.Add("@busDoc", SqlDbType.Int).Value = this.busDoc;
                sqlcmd.Parameters.Add("@busUnd", SqlDbType.Int).Value = this.busUnd;
                sqlcmd.Parameters.Add("@busEx", SqlDbType.Int).Value = this.busEx;
                sqlcmd.Parameters.Add("@busDev", SqlDbType.Int).Value = this.busGen;
                sqlcmd.Parameters.Add("@impGen", SqlDbType.Int).Value = this.impGen;
                sqlcmd.Parameters.Add("@impDoc", SqlDbType.Int).Value = this.impDoc;
                sqlcmd.Parameters.Add("@impRes", SqlDbType.Int).Value = this.impRes;
                sqlcmd.Parameters.Add("@impTec", SqlDbType.Int).Value = this.impTec;
                sqlcmd.Parameters.Add("@impEx", SqlDbType.Int).Value = this.impEx;
                sqlcmd.Parameters.Add("@impDev", SqlDbType.Int).Value = this.impDev;
                sqlcmd.Parameters.Add("@quaGen", SqlDbType.Int).Value = this.quaGen;
                sqlcmd.Parameters.Add("@quaRes", SqlDbType.Int).Value = this.quaRes;
                sqlcmd.Parameters.Add("@quaUnd", SqlDbType.Int).Value = this.quaUnd;
                sqlcmd.Parameters.Add("@quaEx", SqlDbType.Int).Value = this.quaEx;
                sqlcmd.Parameters.Add("@quaDev", SqlDbType.Int).Value = this.quaDev;
                sqlcmd.Parameters.Add("@quaCon", SqlDbType.Int).Value = this.quaCon;
                sqlcmd.Parameters.Add("@sumCos", SqlDbType.Int).Value = this.sumCos;
                sqlcmd.Parameters.Add("@sumBus", SqlDbType.Int).Value = this.sumBus;
                sqlcmd.Parameters.Add("@sumImp", SqlDbType.Int).Value = this.sumImp;
                sqlcmd.Parameters.Add("@sumQua", SqlDbType.Int).Value = this.sumQua;
                sqlcmd.Parameters.Add("@total", SqlDbType.Int).Value = this.total;
                sqlcmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dữ liệu đã tồn tại hoặc không hợp lệ!!!" + ex.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }

        public void updateReqRisk()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("updateReqRisk", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idProject", SqlDbType.Int).Value = this.idProject;
                sqlcmd.Parameters.Add("@idReq", SqlDbType.NVarChar).Value = this.idReq;
                sqlcmd.Parameters.Add("@cusCos", SqlDbType.Int).Value = this.cusCos;
                sqlcmd.Parameters.Add("@cusFun", SqlDbType.Int).Value = this.cusFun;
                sqlcmd.Parameters.Add("@cusCom", SqlDbType.Int).Value = this.cusCom;
                sqlcmd.Parameters.Add("@cusGen", SqlDbType.Int).Value = this.cusGen;
                sqlcmd.Parameters.Add("@cusDoc", SqlDbType.Int).Value = this.cusDoc;
                sqlcmd.Parameters.Add("@busCos", SqlDbType.Int).Value = this.busCos;
                sqlcmd.Parameters.Add("@busFun", SqlDbType.Int).Value = this.busFun;
                sqlcmd.Parameters.Add("@busGen", SqlDbType.Int).Value = this.busGen;
                sqlcmd.Parameters.Add("@busDoc", SqlDbType.Int).Value = this.busDoc;
                sqlcmd.Parameters.Add("@busUnd", SqlDbType.Int).Value = this.busUnd;
                sqlcmd.Parameters.Add("@busEx", SqlDbType.Int).Value = this.busEx;
                sqlcmd.Parameters.Add("@busDev", SqlDbType.Int).Value = this.busGen;
                sqlcmd.Parameters.Add("@impGen", SqlDbType.Int).Value = this.impGen;
                sqlcmd.Parameters.Add("@impDoc", SqlDbType.Int).Value = this.impDoc;
                sqlcmd.Parameters.Add("@impRes", SqlDbType.Int).Value = this.impRes;
                sqlcmd.Parameters.Add("@impTec", SqlDbType.Int).Value = this.impTec;
                sqlcmd.Parameters.Add("@impEx", SqlDbType.Int).Value = this.impEx;
                sqlcmd.Parameters.Add("@impDev", SqlDbType.Int).Value = this.impDev;
                sqlcmd.Parameters.Add("@quaGen", SqlDbType.Int).Value = this.quaGen;
                sqlcmd.Parameters.Add("@quaRes", SqlDbType.Int).Value = this.quaRes;
                sqlcmd.Parameters.Add("@quaUnd", SqlDbType.Int).Value = this.quaUnd;
                sqlcmd.Parameters.Add("@quaEx", SqlDbType.Int).Value = this.quaEx;
                sqlcmd.Parameters.Add("@quaDev", SqlDbType.Int).Value = this.quaDev;
                sqlcmd.Parameters.Add("@quaCon", SqlDbType.Int).Value = this.quaCon;
                sqlcmd.Parameters.Add("@sumCos", SqlDbType.Int).Value = this.sumCos;
                sqlcmd.Parameters.Add("@sumBus", SqlDbType.Int).Value = this.sumBus;
                sqlcmd.Parameters.Add("@sumImp", SqlDbType.Int).Value = this.sumImp;
                sqlcmd.Parameters.Add("@sumQua", SqlDbType.Int).Value = this.sumQua;
                sqlcmd.Parameters.Add("@total", SqlDbType.Int).Value = this.total;
                sqlcmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dữ liệu đã tồn tại hoặc không hợp lệ!!!" + ex.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }

        public void deleteReqRiskByIdProject()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("deleteRiskByIdProject", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                //sqlcmd.Parameters.Add("@idReq", SqlDbType.NVarChar).Value = this.idReq;
                sqlcmd.Parameters.Add("@idProject", SqlDbType.Int).Value = this.idProject;
                sqlcmd.ExecuteNonQuery();
                //MessageBox.Show("You have delete success !!!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                MessageBox.Show("You have error while deleting project!!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }

        public static DataTable checkReqRisk(String strSQL)
        {
            try
            {
                
                clsConnect ketnoi = new clsConnect();
                ketnoi.openConnection();
                SqlDataAdapter da = new SqlDataAdapter(strSQL, ketnoi.Connection);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
                ketnoi.closeConnection();
            }
            catch
            {
                return null;
            }
        }
        public DataTable getDataReqRisk(String strSQL)
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            SqlDataAdapter da = new SqlDataAdapter(strSQL, ketnoi.Connection);
            DataTable dt = new DataTable();
            da.Fill(dt);
            ketnoi.closeConnection();
            return dt;
        }
    }
}
